/**
 * 
 */
package org.okhati.www.model;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author sujan
 *
 */
public class InstitutionRegistry {

	private static InstitutionRegistry institutionRegistry;

	private final Map<String, String> institutionTypeMap = new HashMap<String, String>();

	private List<Institution> institutions = new ArrayList<Institution>();

	private InstitutionRegistry() {

	}

	public static InstitutionRegistry getInstance() {
		if(institutionRegistry == null) {
			institutionRegistry = new InstitutionRegistry();
		}
		return institutionRegistry;
	}

	public void addInstitution(Institution institution) {
		institutions.add(institution);
	}

	public List<Institution> getInstitutions() {
		return institutions;
	}

	public void addToMap(String sn, String type) {
		institutionTypeMap.put(sn, type);
	}

	public boolean knowsType(String sn) {
		return institutionTypeMap.containsKey(sn);
	}

	public String getType(String sn) {
		return institutionTypeMap.get(sn);
	}

	public void printInstitutions() {
		for(Institution institution: institutions) {
			System.out.println(institution);
		}
	}

	public List<String> getDistricts() {
		List<String> districts = new ArrayList<String>();
		for (Institution institution : institutions) {
			if(!districts.contains(institution.getDistrict())) {
				districts.add(institution.getDistrict());
			}
		}
		return districts;
	}

	public List<String> getCities() {
		List<String> cities = new ArrayList<String>();
		for (Institution institution : institutions) {
			if(!cities.contains(institution.getCity())) {
				cities.add(institution.getCity());
			}
		}
		return cities;
	}

	/**
	 * @param readFile
	 */
	public void setInstitutions(List<Institution> institutions) {
		this.institutions = institutions;
	}
}
